<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="js/jquery-2.0.3.js"></script>
    <title>仿小米商城轮播图</title>
    <style>
        * {
            padding: 0;
            margin: 0;
            box-sizing: border-box;
        }

        ul li {
            list-style: none;
        }

        #container {
            height: 461px;
            width: 994px;
            margin: 100px auto;
            /*overflow: hidden;*/
            position: relative;
        }

        #container .carousel {
            height: 461px;
            width: 4970px;
            position: absolute;
        }

        #container .carousel li {
            display: inline-block;
            height: 461px;
            width: 994px;
            position: absolute;
            left: 0;
            top: 0;
            /*opacity: 0;*/
        }

        #container .carousel .active {
            opacity: 1;
        }

        #container .carousel li img {
            height: 461px;
            width: 994px;
        }

        #container .btn-left,
        #container .btn-right {
            display: inline-block;
            height: 72px;
            line-height: 71px;
            text-align: center;
            width: 42px;
            position: absolute;
            font-size: 30px;
            color: #d5d4d4;
        }

        #container .btn-left:hover,
        #container .btn-right:hover {
            background-color: #333;
            color: #ffffff;
            opacity: 0.5;
        }

        #container .btn-left {
            top: calc(50% - 36px);
            left: 0;
        }

        #container .btn-right {
            top: calc(50% - 36px);
            right: 0;
        }

        /*小圆点*/
        #point {
            position: absolute;
            bottom: 25px;
            right: 35px;
        }

        #point li {
            display: inline-block;
            height: 10px;
            width: 10px;
            margin: 0 5px;
            border-radius: 50%;
            border: solid 2px #b2adac;
        }
    </style>
</head>
<script>
    $(function () {

        var num = 0;
        var length = $('.carousel li').length - 1;
//        左侧按钮
        $('.btn-left').click(function () {
            if (num < length) {
                num++;
            } else {
                num = 0;
            }
            $('.carousel li').eq(num).fadeIn().siblings().fadeOut();
            $('#point li').eq(num).css('background-color', '#8c8584').siblings().css('background-color', 'transparent')
        })
//        右侧按钮
        $('.btn-right').click(function () {
            if (num < length) {
                num++;
            } else {
                num = 0;
            }
            $('.carousel li').eq(num).fadeIn().siblings().fadeOut();
            $('#point li').eq(num).css('background-color', '#8c8584').siblings().css('background-color', 'transparent');
        })
//        自动轮播
        function auto() {
            if (num < length) {
                num++;
            } else {
                num = 0;
            }
            $('.carousel li').eq(num).fadeIn().siblings().fadeOut();
            $('#point li').eq(num).css('background-color', '#8c8584').siblings().css('background-color', 'transparent');
        }

        var timer = setInterval(auto, 3000);
        $('.carousel').hover(function () {
            clearInterval(timer);
        }, function () {
             timer = setInterval(auto, 3000);
        })
    })

</script>
<body>
<div id="container">
    <ul class="carousel">
        <li class="active"><img src="images/1.jpg" alt=""></li>
        <li><img src="images/2.jpg" alt=""></li>
        <li><img src="images/3.jpg" alt=""></li>
        <li><img src="images/4.jpg" alt=""></li>
        <li><img src="images/5.jpg" alt=""></li>
    </ul>
    <span class="btn-left">＜</span>
    <span class="btn-right">＞</span>
    <ul id="point">
        <li></li>
        <li></li>
        <li></li>
        <li></li>
        <li></li>
    </ul>
</div>

</body>
</html>